<?php


class LiveChannel extends CActiveRecord
{
        public $Vvamjdmvic5i;
        public $Vif53wwzmbl1;
        public $Vvzhqgqf4t4p;
        public $V0b1ihlordvk;
        public $Var5itcrymel;
        public $Vrwxpiewut2t;
        public $V54a4mp5olw3;





        public $Vjule3ystjlm;
        public $Vlmv1jwbdio0;
        public $Vl4ul3ugim3b;
        public $Vtafxfbizgvb;
        public $Vpu0sywyhduk;
        public $Vp0ht3ph2ayz;
        public $Vllfux5zg3zw;
        public $Vexzyyshqy31;
        public $Vupdrt5bepub;
        public $Vlex1odmypqh;
        public $V3vfejo0ab2u;
        public $V1gg0mbt0vuj;
        public $Vg1i52mnj5wl;
        public $V1zxr3va0asx;
        public $Vpewxjnsgcdl;
        public $V3cb53weuyqt;
        public $Vmhcvb2s01eg;
        public $V2y313ejjatz;
        public $Vptq42jjrywe;
        
	
	public static function model($Vgmajjibziuy=__CLASS__)
	{
		return parent::model($Vgmajjibziuy);
	}

	
	public function tableName()
	{
		return 'live_channel';
	}

	
	public function rules()
	{
		
		
		return array(
			array('code_name, display_name, create_date, modify_date', 'required'),
			array('view_count, like_count, dislike_count, rating_count, comment_count, favorite_count, honor, status, is_multibitrate, is_trailer_multibitrate, trailer_stream_count, live_stream_count, image_count, is_free, create_user_id, modify_user_id', 'numerical', 'integerOnly'=>true),
			array('rating, price', 'numerical'),
			array('code_name, display_name, display_name_ascii', 'length', 'max'=>200),
			array('tags, tags_ascii', 'length', 'max'=>500),
			array('short_description, short_description_ascii, second_screen_url', 'length', 'max'=>300),
			array('description, description_ascii, status_log', 'length', 'max'=>3000),
			array('delete_date', 'safe'),
			
			
			array('id, code_name, display_name, display_name_ascii, tags, tags_ascii, short_description, short_description_ascii, description, description_ascii, view_count, like_count, dislike_count, rating, rating_count, comment_count, favorite_count, status,status_log,honor is_multibitrate, is_trailer_multibitrate, trailer_stream_count, live_stream_count, is_free, price, create_date, modify_date, create_user_id, modify_user_id', 'safe', 'on'=>'search'),
                        array('code_name','unique','message'=>'{attribute}:{value} already exists!'),

		);
	}

	
	public function relations()
	{
		
		
		return array(
			'liveCategoryChannelMappings' => array(self::HAS_MANY, 'LiveCategoryChannelMapping', 'live_channel_id'),
                        'liveCategories'=>array(self::HAS_MANY,'LiveCategory','live_category_id', 'through'=>'liveCategoryChannelMappings'),
			'createUser' => array(self::BELONGS_TO, 'BackendUser', 'create_user_id'),
			'modifyUser' => array(self::BELONGS_TO, 'BackendUser', 'modify_user_id'),
			'liveChannelPrograms' => array(self::HAS_MANY, 'LiveChannelProgram', 'live_channel_id'),
			'liveComments' => array(self::HAS_MANY, 'LiveComment', 'live_channel_id'),
			'liveImages' => array(self::HAS_MANY, 'LiveImage', 'live_channel_id'),
			'liveLikeDislikes' => array(self::HAS_MANY, 'LiveLikeDislike', 'live_channel_id'),
			'livePackageDetails' => array(self::HAS_MANY, 'LivePackageDetail', 'live_channel_id'),
			'liveRatings' => array(self::HAS_MANY, 'LiveRating', 'live_channel_id'),
			'liveStreams' => array(self::HAS_MANY, 'LiveStream', 'live_channel_id'),
			'liveSubscriberFavorites' => array(self::HAS_MANY, 'LiveSubscriberFavorite', 'live_channel_id'),
                        'liveCategories'=>array(self::HAS_MANY,'LiveCategory','live_category_id', 'through'=>'liveCategoryChannelMappings'),
		);
	}

	
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'code_name' => 'Code Name',
			'display_name' => 'Display Name',
			'display_name_ascii' => 'Display Name Ascii',
			'tags' => 'Tags',
			'tags_ascii' => 'Tags Ascii',
			'short_description' => 'Short Description',
			'short_description_ascii' => 'Short Description Ascii',
			'description' => 'Description',
			'description_ascii' => 'Description Ascii',
			'view_count' => 'View Count',
			'like_count' => 'Like Count',
			'dislike_count' => 'Dislike Count',
			'rating' => 'Rating',
			'rating_count' => 'Rating Count',
			'comment_count' => 'Comment Count',
			'favorite_count' => 'Favorite Count',
			'honor' => 'Honor',
                        'status' =>'Status',
                        'status_log' =>'Status Log',
			'is_multibitrate' => 'Is Multibitrate',
			'is_trailer_multibitrate' => 'Is Trailer Multibitrate',
			'trailer_stream_count' => 'Trailer Stream Count',
			'live_stream_count' => 'Live Stream Count',
                        'image_count' => 'Image Count',
			'is_free' => 'Is Free',
			'price' => 'Price',
			'create_date' => 'Create Date',
			'modify_date' => 'Modify Date',
			'create_user_id' => 'Create User',
			'modify_user_id' => 'Modify User',
			'second_screen_url' => 'Second Screen Url',
			
		);
	}

	
	public function search()
	{
		
		

		$V0v5vsnfxezw=new CDbCriteria;

		$V0v5vsnfxezw->compare('id',$this->id);
		$V0v5vsnfxezw->compare('code_name',$this->code_name,true);
		$V0v5vsnfxezw->compare('display_name',$this->display_name,true);
		$V0v5vsnfxezw->compare('display_name_ascii',$this->display_name_ascii,true);
		$V0v5vsnfxezw->compare('tags',$this->tags,true);
		$V0v5vsnfxezw->compare('tags_ascii',$this->tags_ascii,true);
		$V0v5vsnfxezw->compare('short_description',$this->short_description,true);
		$V0v5vsnfxezw->compare('short_description_ascii',$this->short_description_ascii,true);
		$V0v5vsnfxezw->compare('description',$this->description,true);
		$V0v5vsnfxezw->compare('description_ascii',$this->description_ascii,true);
		$V0v5vsnfxezw->compare('view_count',$this->view_count);
		$V0v5vsnfxezw->compare('like_count',$this->like_count);
		$V0v5vsnfxezw->compare('dislike_count',$this->dislike_count);
		$V0v5vsnfxezw->compare('rating',$this->rating);
		$V0v5vsnfxezw->compare('rating_count',$this->rating_count);
		$V0v5vsnfxezw->compare('comment_count',$this->comment_count);
		$V0v5vsnfxezw->compare('favorite_count',$this->favorite_count);
		$V0v5vsnfxezw->compare('is_active',$this->is_active);
		$V0v5vsnfxezw->compare('is_multibitrate',$this->is_multibitrate);
		$V0v5vsnfxezw->compare('is_trailer_multibitrate',$this->is_trailer_multibitrate);
		$V0v5vsnfxezw->compare('trailer_stream_count',$this->trailer_stream_count);
		$V0v5vsnfxezw->compare('live_stream_count',$this->live_stream_count);
		$V0v5vsnfxezw->compare('image_count',$this->image_count);
		$V0v5vsnfxezw->compare('is_free',$this->is_free);
		$V0v5vsnfxezw->compare('price',$this->price);
		$V0v5vsnfxezw->compare('create_date',$this->create_date,true);
		$V0v5vsnfxezw->compare('modify_date',$this->modify_date,true);
		$V0v5vsnfxezw->compare('create_user_id',$this->create_user_id);
		$V0v5vsnfxezw->compare('modify_user_id',$this->modify_user_id);
		

		$Vu2qvgmgucqi = new CActiveDataProvider($this, array(
			'criteria'=>$V0v5vsnfxezw,
		));
                $Vbzpaejiy0xf = array();
                foreach ($Vu2qvgmgucqi->data AS $Vlqihxrrpwig) {
                     
                     $Vy5lc1awkxbj = $Vlqihxrrpwig->getPath();
                     $Vgmx3z2zle5m = 1;
                     $Vfcisoqdzruw='';
                     foreach ($Vy5lc1awkxbj as $Vth5qpbbfjne) 
                         if ($Vth5qpbbfjne->path!=''){
                             $Vfcisoqdzruw .= '<a href="'.Yii::app()->createUrl("admin/liveCategory/view",array("id"=>$Vth5qpbbfjne->id)).'">'.$Vth5qpbbfjne->getPathName().'</a>'.',';
                             $Vgmx3z2zle5m++;
                         }
                     $Vfcisoqdzruw = substr($Vfcisoqdzruw, 0, -1);
                     $Vlqihxrrpwig->categoryPath = $Vfcisoqdzruw;
                     $Vbzpaejiy0xf = array_merge($Vbzpaejiy0xf, array($Vlqihxrrpwig));
                }
                $Vu2qvgmgucqi->setData($Vbzpaejiy0xf);
                return $Vu2qvgmgucqi;
	}
        
        public function getPath() {
            $V0d2bw3n5vc3 = $this->liveCategories;
            for ($Vgmx3z2zle5m = 0; $Vgmx3z2zle5m < count($V0d2bw3n5vc3); $Vgmx3z2zle5m++) 
                for ($Vgmx3z2zle5m1 = 0; $Vgmx3z2zle5m1 < count($V0d2bw3n5vc3); $Vgmx3z2zle5m1++) {
                    if ($V0d2bw3n5vc3[$Vgmx3z2zle5m]->path !='' && $V0d2bw3n5vc3[$Vgmx3z2zle5m1]->path !='' && strpos('/'.$V0d2bw3n5vc3[$Vgmx3z2zle5m]->path.'/','/'.$V0d2bw3n5vc3[$Vgmx3z2zle5m1]->path.'/')!==FALSE && $Vgmx3z2zle5m!=$Vgmx3z2zle5m1){
                        $V0d2bw3n5vc3[$Vgmx3z2zle5m1]->path='';
                    }
                }
            
            return $V0d2bw3n5vc3;    
        }
        
        public function search2($Vxf5kelta0ig=NULL)
	{
		
		

		$V0v5vsnfxezw=new CDbCriteria;

		$V0v5vsnfxezw->compare('display_name',$this->display_name,true);
		$V0v5vsnfxezw->compare('display_name_ascii',$this->display_name_ascii,true);
		
		$Vu2qvgmgucqi = new CActiveDataProvider($this, array(
			'criteria'=>$V0v5vsnfxezw,"pagination"=>array('pageSize'=>'20')
		));
                $Vbzpaejiy0xf = array();
                
                    foreach ($Vu2qvgmgucqi->data AS $Vlqihxrrpwig) {
                        if ($Vxf5kelta0ig!=NULL) {
                            $V42mbxfwgcig = LivePackageDetail::model()->findByAttributes(array('live_channel_id'=>$Vlqihxrrpwig->id,'live_package_id'=>$Vxf5kelta0ig));
                            if ($V42mbxfwgcig!=NULL) $Vlqihxrrpwig->isInPackage = true;
                        }
                        $Vbzpaejiy0xf = array_merge($Vbzpaejiy0xf,array($Vlqihxrrpwig));
                    }
                return new CArrayDataProvider($Vbzpaejiy0xf,array("pagination"=>array('pageSize'=>'20')));    
	}
	
	public function getListChannelName() {
		$Vjrb01zm4l0i = LiveChannel::model()->findAllByAttributes(array("status"=>1));
		$Vjfnpfxswf1x = array();
		foreach($Vjrb01zm4l0i as $Voaqbpuxzkmy) {
			$Vjfnpfxswf1x[$Voaqbpuxzkmy->id] = $Voaqbpuxzkmy->display_name;
		}
		return $Vjfnpfxswf1x;
	}
}